-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Bucket class #2140
Refactor Bucket class #2140
Conversation
ffa83fe
to
1ad4072
Compare
We used to have Buckets in the main thread. Then #941 moved way from that:
What are the reasons for switching back to having full Buckets in the main thread? |
The We should factor the |
Sounds ok to me I reviewed the changes and it looks good but we should get a second set of 👀 on this before merging. |
I probably won't have a chance to do a deep review here, but this sounds fine to me. |
1ad4072
to
7c41264
Compare
That was mostly about the high level changes which @jfirebaugh already commented on. More review is always good though |
Yes, it does create 8KB buffers for each bucket. My understanding is that we take exactly this approach in mapbox-gl-native. Are there any other optimizations there?
I just ran the buffer benchmark and found a ~40% slowdown. We should investigate and try to ameliorate before merging. |
7c41264
to
38267e0
Compare
Creating and transferring more buffers is more expensive. By tweaking some parameters, I was able to get the buffer benchmark time to within 15% of master. Another potential optimization is to use three[1] instances of [1] one vertex buffer, one element buffer, and one secondElement buffer |
I should note that, after doing parameter tuning, I came to an unintuitive optimal value for |
38267e0
to
5d3aaab
Compare
Sounds good to me. In general, I'd prefer if optimizations to avoid regressions are done before merging into master so that master never regresses.
What did you optimize for? allocation performance or memory usage? That doesn't seem surprising if all that matters is the allocation performance. |
I prefer that too, especially given the recent perf regressions. However, the requirement that PRs do not regress any performance metric by any amount is pretty stiff, especially in the context of these kinds of refactors, which are necessary to ship data-driven styling. I will continue working on optimizing this PR today. As always, I appreciate extra eyes and thoughts on places where we could improve perf here.
I am optimizing for the "buffer benchmark" the source of which is available here. I reckon we can get optimal memory usage with this allocation strategy by "shrinkwrapping" the arrayBuffer.slice(0, this.length * this.itemSize) |
8df61c5
to
80c2acb
Compare
@@ -158,12 +173,18 @@ Buffer.prototype.validate = function(args) { | |||
assert(argIndex === args.length); | |||
}; | |||
|
|||
Buffer.prototype.shrinkwrap = function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, we could call this Buffer#trim
80c2acb
to
7700ecd
Compare
@lucaswoj the buffer optimizations look great. Definitely fast enough for now! thanks It looks like transfers back to the main thread are still slower: bucket-2004:
master:
those times were produced by https://gist.github.com/ansis/572fb5caf1baff2452f7 It looks like this is caused by:
|
fixes #1585
Improves main thread deserialization perf
Bucket#resetBuffers -> Bucket#createBuffers Bucket#addFeatures -> Bucket#populateBuffers
@lucaswoj Looks ready to me! |
477b41b
to
17feae2
Compare
ref #1932
fixes #2004
fixes #1585
Bucket
s from the worker to the main threadElementGroups
intoBucket
Buffer#EXTENT
toBucket#EXTENT
or elsewherebuilder
s tobuffer
s inbuffer.test.js